package com.example.aqs;

import java.util.concurrent.locks.AbstractQueuedSynchronizer;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author shanchong
 * @date 2021/2/21
 **/
public class MyAqs extends AbstractQueuedSynchronizer {

    private volatile int state = 0;

    public static void main(String[] args) {
        MyAqs myAqs = new MyAqs();
        myAqs.acquire(1);
        ReentrantLock reentrantLock = new ReentrantLock();
        reentrantLock.lock();
    }

    @Override
    protected boolean tryAcquire(final int arg) {
        if (state==0) {
            state++;
            return true;
        }
        return false;
    }

    @Override
    protected boolean tryRelease(final int arg) {
        state=0;
        return true;
    }
}
